package chapter14;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/22 21:14
 */
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "id")
class Common {
    public String name;
}

class A {
    public Common first;
    public Common second;
}

public class JacksonTest {
    public static void main(String[] args) {
        Common common = new Common();
        common.name = "test";
        A a = new A();
        a.first = common;
        a.second = common;

        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        try {
            String json = mapper.writeValueAsString(a);
            System.out.println(json);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }


}
